local zhiba = fk.CreateSkill({
  name = "lingling__zhiba",
})

Fk:loadTranslationTable{
  ["lingling__zhiba"] = "制霸",
  [":lingling__zhiba"] = "当你使用【杀】指定目标后，你可以与其拼点，若你赢，本回合你下一次对其造成的伤害+1，若你没赢，"..
  "其下回合下一次对你造成的伤害+1。不能叠加。",

  ["@@lingling__zhiba-turn"] = "制霸",
  ["#lingling__zhiba-invoke"] = "制霸：你可以与 %dest 拼点，若赢，本回合你下次对其伤害+1，若没赢，其下回合对你伤害+1",
}

zhiba:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhiba.name) and
      data.card.trueName == "slash" and player:canPindian(data.to)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = zhiba.name,
      prompt = "#lingling__zhiba-invoke::"..data.to.id,
    }) then
      event:setCostData(self, {tos = {data.to}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pindian = player:pindian({data.to}, zhiba.name)
    if pindian.results[data.to].winner == player then
      room:addTableMarkIfNeed(player, "@@lingling__zhiba-turn", data.to.id)
    else
      room:addTableMarkIfNeed(data.to, zhiba.name, player.id)
    end
  end,
})

zhiba:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    return target == player and table.contains(player:getTableMark("@@lingling__zhiba-turn"), data.to.id)
  end,
  on_use = function (self, event, target, player, data)
    player.room:removeTableMark(player, "@@lingling__zhiba-turn", data.to.id)
    data:changeDamage(1)
  end,
})

zhiba:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark(zhiba.name) ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local mark = table.filter(player:getTableMark(zhiba.name), function (id)
      return not room:getPlayerById(id).dead
    end)
    if #mark > 0 then
      room:setPlayerMark(player, "@@lingling__zhiba-turn", mark)
    end
    room:setPlayerMark(player, zhiba.name, 0)
  end,
})

return zhiba
